package com.family.gmall.mq.controller;

import com.family.gmall.common.result.Result;
import com.family.gmall.common.service.RabbitService;
import com.family.gmall.mq.config.DeadLetterMqConfig;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Auther: family
 * @Date: 2023/8/6 18:16
 * @Description:
 */
@RestController
@RequestMapping("/mq")
@Slf4j
public class MqController {

    @Resource
    private RabbitService rabbitService;

    @Resource
    private RabbitTemplate rabbitTemplate;

    @ApiOperation("消息发送")
    @GetMapping("sendConfirm")
    public Result sendConfirm() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        rabbitService.sendMessage("exchange.confirm", "routing.confirm", sdf.format(new Date()));
        return Result.ok();
    }

    @GetMapping("sendDeadLettle")
    public Result sendDeadLettle() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        this.rabbitTemplate.convertAndSend(DeadLetterMqConfig.exchange_dead, DeadLetterMqConfig.routing_dead_1, "ok");
        System.out.println(sdf.format(new Date()) + "Delay sent.");
        return Result.ok();
    }


}
